{{- define "vsphere_csi_config" }}
{{- $providerClusterConfiguration := .Values.cloudProviderVsphere.internal.providerClusterConfiguration | required "internal.providerClusterConfiguration is required" }}
{{- $vsphereDiscoveryData := .Values.cloudProviderVsphere.internal.vsphereDiscoveryData | required "internal.vsphereDiscoveryData is required" }}
[Global]
user = {{ $providerClusterConfiguration.provider.username | quote }}
password = {{ $providerClusterConfiguration.provider.password | quote }}
insecure-flag = {{ if $providerClusterConfiguration.provider.insecure }}1{{ else }}0{{ end }}
cluster-id = {{ .Values.global.discovery.clusterUUID | quote }}

[VirtualCenter {{ $providerClusterConfiguration.provider.server | quote }}]
datacenters = {{ $vsphereDiscoveryData.datacenter | quote }}
vm-folder-path = {{ $providerClusterConfiguration.vmFolderPath | quote }}

[Labels]
region = {{ $providerClusterConfiguration.regionTagCategory | quote }}
zone = {{ $providerClusterConfiguration.zoneTagCategory | quote }}

{{- end }}

---
apiVersion: v1
kind: Secret
metadata:
  name: csi-controller
  namespace: d8-cloud-provider-vsphere
  {{- include "helm_lib_module_labels" (list . (dict "app" "csi-controller")) | nindent 2 }}
type: Opaque
data:
  cloud-config: {{ include "vsphere_csi_config" . | b64enc | quote }}
